package com.supermarket.business.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.supermarket.business.domain.SupermarketSupplier;
import com.supermarket.business.vo.SupermarketSupplierVO;
import com.supermarket.common.utils.DateUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.supermarket.business.mapper.SupermarketSupplierMapper;
import com.supermarket.business.service.ISupermarketSupplierService;

import javax.annotation.Resource;

/**
 * 供应商Service业务层处理
 * 
 * @author ruoyi
 * @date 2025-07-21
 */
@Service
public class SupermarketSupplierServiceImpl extends ServiceImpl<SupermarketSupplierMapper, SupermarketSupplier> implements ISupermarketSupplierService
{
    @Resource
    private SupermarketSupplierMapper supermarketSupplierMapper;

    /**
     * 查询供应商
     * 
     * @param supplierId 供应商主键
     * @return 供应商
     */
    @Override
    public SupermarketSupplier selectSysSupplierBySupplierId(Long supplierId)
    {
        return supermarketSupplierMapper.selectSysSupplierBySupplierId(supplierId);
    }

    /**
     * 查询供应商列表
     * 
     * @param supermarketSupplier 供应商
     * @return 供应商
     */
    @Override
    public List<SupermarketSupplier> selectSysSupplierList(SupermarketSupplier supermarketSupplier)
    {
        return supermarketSupplierMapper.selectSysSupplierList(supermarketSupplier);
    }

    /**
     * 新增供应商
     * 
     * @param supermarketSupplier 供应商
     * @return 结果
     */
    @Override
    public int insertSysSupplier(SupermarketSupplier supermarketSupplier)
    {
        supermarketSupplier.setCreateTime(DateUtils.getNowDate());
        return supermarketSupplierMapper.insertSysSupplier(supermarketSupplier);
    }

    /**
     * 修改供应商
     * 
     * @param supermarketSupplier 供应商
     * @return 结果
     */
    @Override
    public int updateSysSupplier(SupermarketSupplier supermarketSupplier)
    {
        supermarketSupplier.setUpdateTime(DateUtils.getNowDate());
        return supermarketSupplierMapper.updateSysSupplier(supermarketSupplier);
    }

    /**
     * 批量删除供应商
     * 
     * @param supplierIds 需要删除的供应商主键
     * @return 结果
     */
    @Override
    public int deleteSysSupplierBySupplierIds(Long[] supplierIds)
    {
        return supermarketSupplierMapper.deleteSysSupplierBySupplierIds(supplierIds);
    }

    /**
     * 删除供应商信息
     * 
     * @param supplierId 供应商主键
     * @return 结果
     */
    @Override
    public int deleteSysSupplierBySupplierId(Long supplierId)
    {
        return supermarketSupplierMapper.deleteSysSupplierBySupplierId(supplierId);
    }

    /**
     * 获取供应商VO列表
     * @param supermarketSupplier
     * @return
     */
    @Override
    public List<SupermarketSupplierVO> selectSysSupplierListVO(SupermarketSupplier supermarketSupplier) {
        List<SupermarketSupplier> list = supermarketSupplierMapper.selectSysSupplierList(supermarketSupplier);
        List<SupermarketSupplierVO> listVO = new ArrayList<SupermarketSupplierVO>();
        for (SupermarketSupplier supplier : list) {
            SupermarketSupplierVO vo = new SupermarketSupplierVO();
            BeanUtils.copyProperties(supplier, vo);
            listVO.add(vo);
        }
        return listVO;
    }

    @Override
    public SupermarketSupplierVO selectSysSupplierVOBySupplierId(Long supplierId) {
        SupermarketSupplier supplier = supermarketSupplierMapper.selectSysSupplierBySupplierId(supplierId);
        if (supplier == null) {
            throw new IllegalArgumentException("供应商不存在");
        }
        SupermarketSupplierVO vo = new SupermarketSupplierVO();
        BeanUtils.copyProperties(supplier, vo);
        return vo;
    }
}
